package com.gssbh.framework.toolkit.web;

import com.gssbh.framework.toolkit.web.annotation.*;
import com.gssbh.framework.toolkit.web.constant.ApiPathConstants;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebMvcConfigAutoConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SecurityHandlerInterceptor())
                .addPathPatterns("/api/**");
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer config) {
        config
                .addPathPrefix(ApiPathConstants.EDUCATION_API_PREFIX,
                        a -> a.isAnnotationPresent(EducationApi.class))
                .addPathPrefix(ApiPathConstants.SCHOOL_API_PREFIX,
                        a -> a.isAnnotationPresent(SchoolApi.class))
                .addPathPrefix(ApiPathConstants.TEACHER_API_PREFIX,
                        a -> a.isAnnotationPresent(TeacherApi.class))
                .addPathPrefix(ApiPathConstants.STUDENT_API_PREFIX,
                        a -> a.isAnnotationPresent(StudentApi.class))
                .addPathPrefix(ApiPathConstants.PARENTS_API_PREFIX,
                        a -> a.isAnnotationPresent(ParentsApi.class))


        ;

    }
}
